#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int n,m,k,T;

int las(int num){
	int cnt = 0;
	while(num > 0) {
		cnt++;
		num /= 10;
	}
	return cnt;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> T;
	while(T--) {
		int num = 0;
		int ans = (1LL << 60);
		cin >> num;
		int l = las(num);
		for(int i = 0;i < 10; ++ i) {
			ans = min(ans,num);
			num = num / 10 + num % 10 * pow(10,l-1);
		}
		cout << ans << endl;
	}
	return 0;
}